<template>
	<view class="details">
		<view class="questions-nav" v-if="is_fyplay == 1">
			<view class="questions-nav-title">考试总成绩{{body.fen}}分，本题得{{ info.userfen }}分</view>
			<view class="questions-nav-explain" @click="explainChange(1)">
				<image src="../../static/questions/shuo.png"></image>
				<view>说明</view>
			</view>
		</view>
		
		<All
			:info="info"
			:keys="keys"
			@qinfolaststepChange="qinfolaststepChange"
		></All>
		
		<Function 
			:schedule="info.schedule"
			@playChange  = "playChange"
		></Function>
		<Explain :info="info" v-if="is_explain == 1" @explainChange="explainChange"></Explain>
		<ad unit-id="adunit-e216b11c44862965" bindload="adLoad" binderror="adError" bindclose="adClose"></ad>
	</view>
</template>
<!--  -->
<script>
	import All  from "../../components/record/all.vue"
	import Function from  "../../components/record/examfunction.vue"
	import Explain from "../../components/cell/explain.vue"
	
	export default {
		components:{
			Function,Explain,All
		},
		data() {
			return {
				id : '',
				info: {},
				keys  : [],
				index : null,
				index1 : null,
				questionskey : 0,
				body   : [],
				key    :  0,
				is_fyplay : 0,
				Intervaltime : '',
				is_explain :0,
				rewardedVideoAd : ''
				
 			};
		},
		onLoad(e) {
			let that = this;
			this.id  = e.id;
			this.getall();
			if(wx.createRewardedVideoAd){
			    this.rewardedVideoAd = wx.createRewardedVideoAd({ adUnitId: 'adunit-8091acd63c17665b' })
			    this.rewardedVideoAd.onLoad(() => {
					
			        console.log('onLoad event emit')
			    })
			    this.rewardedVideoAd.onError((err) => {
			        console.log('onError event emit', err)
			    })
			    this.rewardedVideoAd.onClose((res) => {
					var  body   = that.info['body'];
					for(var i=0; i <body.length; i++){
						for(var j=0; j< body[i].length;j++){
							body[i][j]['newuservalue']  =  body[i][j]['value'];
						}
					}
					console.log(body);
					that.info['body']  = body;
					that.body[that.questionskey] = that.info;
			    })
			}
		},
		methods: {
			explainChange(e){
				console.log(e);
				this.is_explain  = e;
			},
			
			playChange(e){ 
				let that =  this;
				if(e==1){
					
					uni.showModal({
						title: '提示',
						content: '观看广告可查看正确答案！',
						success: function (res) {
							if (res.confirm) {
							
								that.rewardedVideoAd.show();
							}
						},
					})
					
				}else if(e==2){
					if(that.questionskey  > 0){
						that.questionskey--;
						that.info  =that.body['body'][that.questionskey];
					}
				}else if(e==3){
					if(that.questionskey +1  < that.body['body'].length){
						that.questionskey++;
						that.info  =that.body['body'][that.questionskey];
					}	
				}
				uni.setNavigationBarTitle({
				    title: that.info.name
				})
			},
			
			
			getall(){
				let that = this;
				that.$exam.getinfo({'id':that.id}).then(res=>{
					var   body = res.data.info['body'];
					for(var i=0; i <body.length; i++){
						console.log(body[i]['body']);
						for(var j=0; j< body[i]['body'].length;j++){
							for(var k=0; k<body[i]['body'][j].length;k++){
								 body[i]['body'][j][k]['newuservalue']  =  body[i]['body'][j][k]['uservalue'];
							}
							
						}
					}
					res.data.info['body'] = body;
					
					that.info  = res.data.info['body'][that.questionskey];
					that.body  = res.data.info;
					uni.setNavigationBarTitle({
					    title: that.info.name
					})
					that.is_fyplay = 1;
					
				})
			}
		}
	}
</script>

<style>
	.questions-nav {
		display: flex;
		padding-right: 16rpx;
		line-height: 120rpx;
		font-size: 40rpx;
		padding-left: 32rpx;
		text-align: left;
	}
	.questions-nav-title {
		flex: 4;
		font-size: 36rpx;
	}
	.questions-nav-right {
		margin: auto;
	}
	.questions-nav-explain {
		padding-left: 20rpx;
		display: flex;
		flex: 1;
		margin-left: auto;
		padding-right: 20rpx;
	}
	.questions-nav-explain > image {
		width: 40rpx;
		height: 40rpx;
		padding-top: 46rpx;
		display: block;
		margin-left: auto;
	}
	.questions-nav-explain > view {
		padding-left: 10rpx;
		color: #3eb8ff;
		font-size: 38rpx;
	}
</style>